#!/bin/bash
#############################################################
# Name:        Supportconfig Plugin for SUSE Studio
# Description: Gathers important troubleshooting information
#              about SUSE Linux Enterprise Studio
# License:     GPLv2
# Author:      Jason Record (jrecord@novell.com)
# Modified:    2010 Oct 21
#############################################################

SVER=1.0.1
RCFILE="/usr/lib/supportconfig/resources/scplugin.rc"
LOG_LINES=500	#0 means include the entire file

[ -s $RCFILE ] && . $RCFILE || { echo "ERROR: Initializing resource file: $RCFILE"; exit 1; }

section_header "Supportconfig Plugin for SUSE Studio, v${SVER}"
RPMLIST="susestudio-ui-server susestudio-thoth sle-studioonsite-release susestudio-rmds flashpolicyd-studio susestudio-common susestudio susestudio-masquerade susestudio-clicfs susestudio-image-helpers susestudio-testdrive susestudio-kiwi-runner nagios-www nagios-plugins-extras nagios nagios-plugins munin munin-node clicfs"
DAEMONLIST="munin-node nagios rmds studio_backgroundrb studio_crontick studio_delayed_job studio_sphinx suse_studio_custom thoth"

if ! rpm -q susestudio susestudio-common &>/dev/null; then
  echo "ERROR: SUSE Studio package(s) not installed"
  echo
  exit 111
fi

for THISRPM in $RPMLIST
do
   validate_rpm $THISRPM
done

plugin_command "cat /proc/meminfo"
plugin_command "free -k"
plugin_command "df -h"
plugin_command "netstat -nlp"

for i in $DAEMONLIST
do
	if [ -s /etc/init.d/$i ]; then
		plugin_command "chkconfig -l $i"
		plugin_command "/etc/init.d/$i status"
		
	fi
done

section_header "UI Server"
pconf_files "/srv/studio/options.yml"
plog_files $LOG_LINES "/srv/studio/ui-server/log/cron_job.log /srv/studio/ui-server/log/production.log /srv/studio/ui-server/log/scheduler.log"

section_header "Kiwi Runner"
pconf_files "/srv/studio/kiwi-runner/config/options.yml"
plog_files $LOG_LINES "/srv/studio/kiwi-runner/log/backgroundrb.log /srv/studio/kiwi-runner/log/production.log"

section_header "Appliance Build Logs"
[ -d /studio/runner/log ] && FILES=$(find /studio/runner/log -type f) || FILES=""
if [ -n "$FILES" ]; then
	plog_files $LOG_LINES $FILES
fi

section_header "Testdrive"
pconf_files "/srv/studio/testdrive/config/options.yml"
plog_files $LOG_LINES "/srv/studio/testdrive/log/production.log"

section_header "RMDS"
pconf_files "/srv/studio/rmds.conf"
plugin_command "grep rmds /var/log/messages | grep -v Ping | grep -v Destroying\ socket"

section_header "THOTH"
pconf_files "/srv/studio/thoth.conf"
plugin_command "grep thoth /var/log/messages"

section_header "Apache Logs"
plog_files $LOG_LINES "/var/log/apache2/rcapache2.out /var/log/apache2/error_log"

section_header "Nagios"
pconf_files "/etc/nagios/nagios.cfg /etc/nagios/objects/contacts.cfg"

section_header "Munin"
pconf_files "/etc/munin/munin.conf"


